
#include "Player.h"

__BEGIN_NAMESPACE_DECL_

Player::Player()
    : _xpos(0.0), _ypos(0.0), _zpos(0.0), _viewAngle(0.0),
      _pitch(0.0), _bobAngle(0.0), _bias(0.0), _unitsPerFoot(12.0)
{
}

void
Player::reset()
{
    _xpos = _ypos = _zpos = 0.0;
    _viewAngle = 0.0;
    _pitch = 0.0;
    _bobAngle = 0.0;
    _bias = 0.0;
}

void
Player::setUnitsPerFoot(double unitsPerFoot)
{
    _unitsPerFoot = unitsPerFoot;
}

void
Player::setPosition (double xpos, double ypos, double zpos)
{
    _xpos = xpos; _ypos = ypos; _zpos = zpos;
}

void
Player::moveForward () 
{ 
    _xpos -= sin(_viewAngle*M_PI/180.0) * MOVE_UNIT_INCR * _unitsPerFoot; 
    _zpos -= cos(_viewAngle*M_PI/180.0) * MOVE_UNIT_INCR * _unitsPerFoot;

    _bobAngle = fmod(_bobAngle + 10.0, 360.0);
    _bias = cos(_bobAngle*M_PI/180.0) * MOVE_UNIT_INCR * _unitsPerFoot;
}

void
Player::moveBackward () 
{ 
    _xpos += sin(_viewAngle*M_PI/180.0) * MOVE_UNIT_INCR * _unitsPerFoot; 
    _zpos += cos(_viewAngle*M_PI/180.0) * MOVE_UNIT_INCR * _unitsPerFoot;

    _bobAngle = fmod(_bobAngle - 10.0, 360.0);
    _bias = cos(_bobAngle*M_PI/180.0) * MOVE_UNIT_INCR * _unitsPerFoot;
}

void
Player::moveLeft () 
{ 
    _xpos -= cos(_viewAngle*M_PI/180.0) * MOVE_UNIT_INCR * _unitsPerFoot; 
    _zpos -= sin(_viewAngle*M_PI/180.0) * MOVE_UNIT_INCR * _unitsPerFoot;
}

void
Player::getPosition (double& xpos, double& ypos, double& zpos) const
{
    xpos = _xpos; ypos = _ypos + _bias; zpos = _zpos;
}

void
Player::moveRight () 
{ 
    _xpos += cos(_viewAngle*M_PI/180.0) * MOVE_UNIT_INCR * _unitsPerFoot; 
    _zpos += sin(_viewAngle*M_PI/180.0) * MOVE_UNIT_INCR * _unitsPerFoot;
}

__END_NAMESPACE_DECL_
